<template>
    <framework title="新闻中心" :bg="require('@/assets/img/news-header.png')"
             :show-search="true" @search="onSearch"  :path="[{name:'新闻中心',path:'/newsCenter'}]" :wrap-style="{background: '#FFFFFF'}">
        <div class="news_list_box">
            <div class="box" v-for="r in searchResult">
                <div class="news_list_box_header">
                    <div class="left" @click="()=>$router.push({ name: 'AllDetails', query: {id:r.id,type:2}})">
                        <div class="title f2">{{ r.title }}</div>
                        <div class="right f3">
                            <span>{{ r.updateTime }}</span>
                            <p >
                                {{ $t('index.newsCenter.detailsButton') }}
                            </p>
                        </div>
                    </div>
                </div>
                <div class="image" v-if="r.img">
                    <img :src="r.img" alt="" @click="()=>$router.push({ name: 'AllDetails', query: {id:r.id,type:2}})">
                </div>
            </div>
        </div>
        <div class="page">
            <van-pagination v-model="page.pageNum" :page-count="page.pageCount" mode="simple" @change="searchData"/>
        </div>
    </framework>
</template>

<script>
import framework from "@/components/framework.vue"

export default {
    name: "NewsCenter",
    components: {
        framework
    },
    data() {
        return {
            search: {
                title: "",
                type: 0
            },
            page: {
                pageNum: 1,
                pageCount: 10
            },
            searchResult: []
        }
    },
    mounted() {
        this.searchData();
    },
    methods: {
        async searchData() {
            let data = await this.$http.get("/newsArticle/list", {
                params: {
                    ...this.search,
                    page: this.page.pageNum
                }
            })
            this.page.pageNum = data.page.currPage;
            this.page.pageCount = data.totalPage;
            this.searchResult = data.page.list;
        },
        onSearch(e) {
            this.search.title = e;
            this.searchData();
        }
    }
}
</script>

<style lang="less"></style>
